package router

import (
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"

	"dustbe/controller/blog"
	"dustbe/controller/cv"
	"dustbe/controller/home"
	"dustbe/controller/kcloud"
	"dustbe/controller/kd"
	"dustbe/controller/knowledgeGraph"
	"dustbe/controller/lowlevelcv"
	"dustbe/controller/me"
	"dustbe/controller/password"
	"dustbe/controller/slidev"
	"dustbe/controller/test"
	"dustbe/controller/thirdparty"
	"dustbe/controller/user"
	"dustbe/controller/music"
	"dustbe/controller/llm"
)

var store = cookie.NewStore([]byte("login"))

func SetupRouter() *gin.Engine {
	// 路由定义
	mainRouter := gin.Default()

	// 中间件
	mainRouter.Use(sessions.Sessions("sessionId", store))

	// 密码接口
	passwordRouter := mainRouter.Group("/api/password")
	{
		passwordRouter.GET("/check-blog-password", password.CheckBlogPassword)
	}

	// 首页
	homeRouter := mainRouter.Group("/api/home")
	{
		homeRouter.GET("/get-server-info", home.GetServerInfo)
		homeRouter.GET("/get-news", home.GetNews)
	}

	// 用户相关 登录注册
	userRouter := mainRouter.Group("/api/user")
	{
		userRouter.GET("/sign-up", user.SignUp)
		userRouter.GET("/sign-in", user.SignIn)
		userRouter.GET("/logout", user.Logout)
		userRouter.GET("/modify-user-info", user.ModifyUserInfo)
		userRouter.GET("/get-user-location", user.GetUserLocation)
	}

	// 锦恢本人信息的路由
	meRouter := mainRouter.Group("/api/me")
	{
		meRouter.GET("/zhihu-column", me.ZhihuColumn)
		meRouter.GET("/bilibili-bangumi", me.BiliBiliBangumi)
		meRouter.GET("/dev-log", me.DevLog)
		meRouter.GET("/todo-list", me.Todo)
		meRouter.GET("/learn-progress", me.LearnProgress)
		meRouter.GET("/project", me.Project)
		meRouter.GET("/open-source", me.OpenSource)
		meRouter.GET("/for-haru", me.SendForHaru)
	}

	// cv 技术接口
	cvRouter := mainRouter.Group("/api/cv")
	{
		cvRouter.POST("/sr", cv.SR)
		cvRouter.GET("/srQuery", cv.SRQuery)
	}

	// knowledge graph 技术接口
	kgRouter := mainRouter.Group("/api/kg")
	{
		kgRouter.GET("/kg-node-query", knowledgeGraph.QueryNode)
		kgRouter.GET("/kg-relation-query", knowledgeGraph.QueryRelation)
	}

	// kmarkdown 技术接口
	kdRouter := mainRouter.Group("/api/kd")
	{
		kdRouter.GET("/get-print-component", kd.GetPrintComponent)
	}

	// kcloud 接口
	kcloudRoute := mainRouter.Group("/api/kcloud")
	{
		kcloudRoute.POST("/store-upload", kcloud.StoreUpload)
		kcloudRoute.GET("/store-download", kcloud.StoreDownload)
	}

	// 低阶图像处理算法技术接口
	lowlevelcvRoute := mainRouter.Group("/api/lowlevelcv")
	{
		lowlevelcvRoute.POST("/coh", lowlevelcv.COH)
		lowlevelcvRoute.POST("/darkdehaze", lowlevelcv.DarkDehaze)
	}

	// 博客系统接口
	blogRoute := mainRouter.Group("/api/blog")
	{
		blogRoute.GET("/init-blog", blog.InitQuery)

		// 未来丢弃 (0/2)
		blogRoute.GET("/range-query-blog", blog.QueryRangeBlog)
		blogRoute.GET("/fetch-blog", blog.FetchArticleByName)

		blogRoute.GET("/range-query-blog-by-pageId", blog.QueryBlogsByPageId)
		blogRoute.GET("/fetch-blog-by-seq", blog.FetchArticleBySeq)

		blogRoute.POST("/create-blog", blog.CreateBlog)
		blogRoute.GET("/delete-blog-by-seq", blog.DeleteBlogBySeq)
		blogRoute.POST("/modify-blog-by-seq", blog.ModifyBlogBySeq)
		blogRoute.GET("/search-by-names", blog.SearchBlogsByNames)

		blogRoute.GET("/simple-recommand-by-name", blog.SimpleRecommand)
		blogRoute.GET("/search-by-tags", blog.SearchByTags)
		blogRoute.GET("/range-query-blog-by-topic", blog.QueryRangeBlogByTopicName)
		blogRoute.GET("/get-hot-topics", blog.GetHotTopics)

		// 博客评论区接口
		blogRoute.POST("/publish-comment", blog.PublishComment)
		blogRoute.POST("/delete-comment", blog.DeleteComment)
		blogRoute.GET("/modify-comment", blog.ModifyComment)
		blogRoute.GET("/get-comment-by-blog-seq", blog.GetCommentsByBlogSeq)
		blogRoute.GET("/get-aministrater-name", blog.GetAdministraterName)
	}


	// PPT 接口
	pptRoute := mainRouter.Group("/api/slidev")
	{
		pptRoute.GET("/init-ppt", slidev.InitQuery)
		pptRoute.GET("/range-query-ppt", slidev.QueryRangeBlog)
	}

	// 测试接口
	testRouter := mainRouter.Group("/api/test")
	{
		testRouter.GET("/hello", test.Hello)
		testRouter.GET("/get-picture", test.GetPicture)
		testRouter.GET("/get-info-after-ns", test.GetInfoAfterNS)
	}

	// 第三方服务
	thirdpartyRouter := mainRouter.Group("/api/thirdparty")
	{
		thirdpartyRouter.GET("/random-image-url", thirdparty.GetRandomImageUrl)
		thirdpartyRouter.GET("/get-city-weather", thirdparty.GetCityWeather)
		thirdpartyRouter.GET("/get-city-weather-by-ip", thirdparty.GetCityWeatherByIP)
	}

	// llm
	llmRouter := mainRouter.Group("/api/llm")
	{
		llmRouter.POST("/get-chatgpt-answer", llm.GetChatgptAnswer)
		llmRouter.GET("/resume-chatgpt-conversion", llm.ResumeChatgptConversion)
	}

	musicRouter := mainRouter.Group("/api/music")
	{
		musicRouter.POST("/publish-staff", music.PublishStaff)
		musicRouter.POST("/delete-staff", music.DeleteStaff)
		musicRouter.POST("/modify-staff", music.ModifyStaff)
		musicRouter.GET("/query-staffs-by-pageId", music.QueryStaffsByPageId)
		musicRouter.GET("/init-staff", music.InitStaff)
		musicRouter.GET("/get-staff-by-id", music.GetStaffById)
	}

	return mainRouter
}
